package adv41;

/**
 * @author oldliu
 * @since 1.0
 */
public class Thread4 extends Thread {
    public Thread4(String name){
        super(name);
    }
    @Override
    public void run() {
        for (int i = 1; i <= 20; i++) {
            System.out.println(this.getName()+" print "+i);
        }
    }

    public static void main(String[] args) {
        //join的用法
        Thread []th=new Thread[5];
        for (int i =0; i <th.length ; i++) {
            th[i]=new Thread4("Thread-"+i);
            th[i].start();
        }
        //主线程等待这5个线程执行完
        for (int t = 0; t < th.length; t++) {
            try {
                th[t].join();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
        System.out.println("打印结束了。。。");
    }
}
